package sk.velkavrana.app.util;

import javax.swing.*;
import java.awt.*;

/**
 * @author mtymes
 * @since May 14, 2009 4:05:00 PM
 */
public class UIUtil {
    public static void initUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
//            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
    }


    public static JFrame createFrame(String title, int width, int height) {
        return createFrame(title, width, height, true);
    }


    public static JFrame createFrame(String title, int width, int height, boolean exitOnClose) {
        JFrame frame = new JFrame(title);

        frame.setSize(width, height);

        if (exitOnClose) {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }

        return frame;
    }


    public static void center(Window window) {
        Toolkit toolkit = Toolkit.getDefaultToolkit();

        Dimension resolution = toolkit.getScreenSize();
        Dimension frameSize = window.getSize();

        int xLocation = resolution.width / 2 - frameSize.width / 2;
        int yLocation = resolution.height / 2 - frameSize.height / 2;

        window.setLocation(xLocation, yLocation);
    }


    public static void show(Window window) {
        window.setVisible(true);
    }
}
